<?php

/*
 * Created on Dec 1, 2011
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
$con = mysql_connect("localhost", "root", "bytewalla5");
if (!$con) {
	die('Could not connect: ' . mysql_error());
}

mysql_select_db("wsn", $con);


$result = mysql_query("SELECT spot_id, spotname FROM sunspot");
$init_spot = null;
									
while ($row = mysql_fetch_array($result)) {
	$init_spot .= "<option value=".$row["spot_id"]." >".$row["spotname"]."</option>";
}

mysql_close($con);
?>

<!DOCTYPE html>
<html lang="en">
<head>
<title>Data Management</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<script type="text/javascript" src="js/jquery-1.6.js" ></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/cufon-replace.js"></script>
<script type="text/javascript" src="js/Swis721_Cn_BT_400.font.js"></script>
<script type="text/javascript" src="js/Swis721_Cn_BT_700.font.js"></script>
<script type="text/javascript" src="js/tabs.js"></script>
<!--[if lt IE 9]>
  	<script type="text/javascript" src="js/html5.js"></script>
	<style type="text/css">
		.bg{ behavior: url(js/PIE.htc); }
	</style>
<![endif]-->
<!--[if lt IE 7]>
		<div style=' clear: both; text-align:center; position: relative;'>
			<a href="http://www.microsoft.com/windows/internet-explorer/default.aspx?ocid=ie6_countdown_bannercode"><img src="http://www.theie6countdown.com/images/upgrade.jpg" border="0"  alt="" /></a>
		</div>
<![endif]-->
</head>
<body id="page5">
	<div class="body1">
	<div class="body2">
	<div class="body5">
		<div class="main">
<!-- header -->
			<?php include("wsnheader.html"); ?>
<!-- header end-->
		</div>
	</div>
	</div>
	</div>
	<div class="body3">
		<div class="main">
<!-- content -->
			<article id="content">
				<div class="wrapper">
					<section class="col1">
						<h2 class="under">Data Management</h2>
						<form id="wsn_stats" action="datacontrol.php" method="post">
						<div>
							<div  class="wrapper">
								<span>Sunspot:</span>
								<select id="sunspotselect" name="sunspot">
								    <option value="-1">--select--</option>
									<?php echo $init_spot; ?>
								</select>
							</div>
							
							<div  class="wrapper">
								<span>Start Time:</span>
								<select id="startselect" name="start">
									<option>--select--</option>
								</select>
							</div>
							
							<div class="wrapper">
								<span>End Time:</span>
								<select id="endselect" name="end">
									<option>--select--</option>
								</select>
							</div>
							
							<div  class="wrapper">
								<span>You want :</span>
								
								<input type="radio" id="radio1" checked="checked" name="action" value="distribute" />
								distribute
								<input type="radio" id="radio2"  name="action" value="graph" />graph
								
								<input type="radio" id="radio3"  name="action" value="download" />download
							</div>
							
							<div id="eiddiv" class="wrapper">
								<span>Destination EID:</span>
								<input  class="input" type="input" value="dtn://city.bytewalla.com" name="desteid" />(please give the destination endpoint id)
							</div>
							
							<div id="graphdiv" style="display: none;" class="wrapper">
								<span>Graph Option:</span>
								
								<input type="checkbox" checked="checked" name="graphcb[]" value="temperature" />
								Temperature
								<input type="checkbox" name="graphcb[]" value="light" />Ligte Level
								
								<input type="checkbox" name="graphcb[]" value= "battery"/>Battery
							</div>
							
							<a href="#" onClick="document.getElementById('wsn_stats').submit()">submit</a>
						</div>
						</form>
					</section>
					
				</div>

			</article>
		</div>
	</div>
	
<!-- content end -->
		
<!-- footer -->
			<?php include("footer.html"); ?>
<!-- footer end -->
<script type="text/javascript"> Cufon.now(); </script>
<script>
	$(document).ready(function() {
		tabs.init();
		$("#radio1").click(function(){
  			$("#graphdiv").hide();	
  			$("#eiddiv").show();
  		});
  		$("#radio2").click(function(){
  			$("#graphdiv").show();	
  			$("#eiddiv").hide();
  		});
  		$("#radio3").click(function(){
  			$("#graphdiv").hide();	
  			$("#eiddiv").hide();
  		});
  		
  		$('#sunspotselect').change(function() {
  			if($(this).attr('value')!= -1){
  				 $.post( "datacontrol.php", { spotid: $(this).attr('value')},
			      function( data ) {
			      	
			         $('#startselect').empty().append(data);
			         $('#endselect').empty().append(data);
			      }
			    );
  				
  			}else{
  				$('#startselect').empty().append("<option>--select--</option>");
			    $('#endselect').empty().append("<option>--select--</option>");
  			}
  			
		});
		
  			
	})
	
</script>
</body>
</html>
